import 'package:cloud_phone_manager/provider/AdbDevicesProvider.dart';
import 'package:cloud_phone_manager/utils/CmdUtils.dart';
import 'package:flutter/cupertino.dart';

class ConnectUtils{
  static AdbDeviceInfo? _adbDeviceInfo;

  static final ConnectUtils _instance = ConnectUtils._internal();

  factory ConnectUtils() {
    return _instance;
  }

  static ConnectUtils getInstance(){
    return _instance;
  }

  ConnectUtils._internal(); // 私有构造函数

  AdbDeviceInfo? getCurrentChooseDevices(){
    return _adbDeviceInfo;
  }

  void connectCurrent(){
    _adbDeviceInfo?.connect();
  }

  void disconnectCurrent(){
    _adbDeviceInfo?.disconnect();
  }

  void setCurrentDevices(AdbDeviceInfo? adbDeviceInfo){
    _adbDeviceInfo = adbDeviceInfo;
    if(_adbDeviceInfo != null){
      CmdUtils.deviceSnGetter((success, error, process, successListener) {
        debugPrint("输出日志：${success}，${error}");
        if(success.isNotEmpty && success != "DONE"){
          _adbDeviceInfo?.sn = success.trim();
          debugPrint("sn为：${success}");
        }
      });
    }
  }

}